package game;
import javax.swing.*;


public class GameWindow extends JFrame {
    private GamePanel gamePanel;
    private int initialInterval;
    private int bombChance;
    private int specialFruitChance;

    public GameWindow() {
        setTitle("多线程切水果游戏");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);

        // 显示难度选择对话框
        String[] difficultyOptions = {"简单", "中等", "困难"};
        int choice = JOptionPane.showOptionDialog(this, "请选择游戏难度:", "游戏难度选择",
                JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, difficultyOptions, difficultyOptions[0]);

        switch (choice) {
            case 0: // 简单
                initialInterval = 3000;
                bombChance = 5;
                specialFruitChance = 10;
                break;
            case 1: // 中等
                initialInterval = 2000;
                bombChance = 10;
                specialFruitChance = 15;
                break;
            case 2: // 困难
                initialInterval = 1500;
                bombChance = 20;
                specialFruitChance = 20;
                break;
            default:
                initialInterval = 2000;
                bombChance = 10;
                specialFruitChance = 15;
                break;
        }

        startNewGame();

        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    private void startNewGame() {
        if (gamePanel != null) {
            remove(gamePanel);
        }

        gamePanel = new GamePanel(this, initialInterval, bombChance, specialFruitChance);
        add(gamePanel);
        revalidate();
        repaint();
    }
    public void restartGame() {
        // 在EDT上执行UI操作
        SwingUtilities.invokeLater(() -> {
            startNewGame();
        });
    }
}
